local sheguo = fk.CreateSkill {
  name = "hanqing__sheguo",
}

Fk:loadTranslationTable{
  ["hanqing__sheguo"] = "涉国",
  [":hanqing__sheguo"] = "出牌阶段各限一次，你可以横置并视为使用<a href=':hanqing__vh_alliance'>【纵横捭阖】</a>，"..
  "或进入<a href='hanqing__alliance_href'>合纵</a>状态并视为使用【铁索连环】。",

  ["#hanqing__sheguo"] = "涉国：横置并视为使用【纵横捭阖】，或进入合纵状态并视为使用【铁索连环】",
}

local U = require "packages/hanqing/util"

sheguo:addEffect("viewas", {
  anim_type = "control",
  prompt = "#hanqing__sheguo",
  interaction = function(self, player)
    local all_names = {"hanqing__vh_alliance", "iron_chain"}
    local names = player:getViewAsCardNames(sheguo.name, all_names, nil, player:getTableMark("hanqing__sheguo-phase"))
    if player.chained then
      table.removeOne(names, "hanqing__vh_alliance")
    end
    if U.getAlliance(player) == "vertical" then
      table.removeOne(names, "hanqing__vh_alliance")
    end
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if #cards ~= 0 or self.interaction.data == nil then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = sheguo.name
    return c
  end,
  before_use = function (self, player, use)
    player.room:addTableMark(player, "hanqing__sheguo-phase", use.card.trueName)
    if self.interaction.data == "hanqing__vh_alliance" then
      player:setChainState(true)
    else
      U.setAlliance(player, "vertical")
    end
  end,
  enabled_at_play = function(self, player)
    return player.phase == Player.Play and #player:getTableMark("hanqing__sheguo-phase") < 2
  end,
})

sheguo:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "hanqing__sheguo-phase", 0)
end)

return sheguo
